<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
</head>

<body>
    <div id="app">


        <!-- 主体 -->


        <div class="css1" v-for="(item,index) in list" :key="item.id">
            <tr>
                <td> 名称:{{item.name}}</td>
                <td> 数量:{{item.num}}</td>
                <td> 单价:{{item.price}}</td>
                <button @click="del(item.id)">删除</button>

            </tr><br>




        </div>
        <tr>
            <td> 总和:{{money}}</td>
        </tr>

    </div>


    <script>
        const app = new Vue({

            el: '#app',
            data: {
                list: [
                    { id: 1, name: '榴莲', num: 2, price: 180, },
                    { id: 2, name: '葡萄', num: 3, price: 60, },
                    { id: 3, name: '樱桃', num: 1, price: 80, },
                    { id: 4, name: '草莓', num: 8, price: 240, },
                    // {},
                    // {},
                    // {},




                ],




            },
            methods: {
                del(id) {
                    this.list = this.list.filter(item => item.id !== id)


                }



            },
            watch: {
                list: {
                    get() {
                        let money = this.list.map(item => item.num * item.price).reduce((a, b) => a + b, 0)
                        return money



                    },
                    set(value) {



                    }




                }





            }









        })





    </script>

</body>

</html>